/**
 * Notes: 项目实体（增强版）
 * Ver : CCMiniCloud Framework 2.0.1 ALL RIGHTS RESERVED BY cclinux0730 (wechat)
 * Date: 2024-03-10 19:20:00 
 */

const BaseModel = require('../config/models_config').base_model;
const BaseProjectModel = require('./base_project_model.js');
const util = require('../../../framework/helpers/util.js');
const timeUtil = require('../../../framework/helpers/time_util.js');
const dataUtil = require('../../../framework/helpers/data_util.js');
const config = require('../../../config/config.js');

class ProjectModelEnhanced extends BaseModel {

    constructor() {
        super();

        // 设置集合名称
        this._collection = BaseProjectModel.C('oa_project');
    }

    /**
     * 获取集合名称
     */
    static getCollectionName() {
        return BaseProjectModel.C('oa_project');
    }

    // 新数据结构定义，包含增强字段
    static DB_STRUCTURE = {
        _pid: 'string|true',
        PROJECT_ID: 'string|true',
        PROJECT_CODE: 'string|true|comment=项目编码',
        PROJECT_NAME: 'string|true|comment=项目名称',
        
        PROJECT_CUSTOMER_ID: 'string|false|comment=客户ID',
        PROJECT_TYPE: 'int|true|default=1|comment=类型：1=新产品开发, 2=客户定制, 3=技术预研, 4=迭代升级',
        PROJECT_STATUS: 'int|true|default=1|comment=状态：1=待立项, 2=立项审核中, 3=已立项, 4=开发中, 5=测试中, 6=客户验证中, 7=量产准备, 8=试产中, 9=量产中, 10=已结项, 11=已取消',
        PROJECT_FLOW_STATUS: 'string|false|comment=研发流程状态：详细流程节点',
        PROJECT_PRIORITY: 'int|true|default=2|comment=优先级：1=低, 2=中, 3=高, 4=紧急',
        PROJECT_DESCRIPTION: 'string|false|comment=描述',
        
        PROJECT_PLAN_START_TIME: 'int|false|comment=计划开始时间',
        PROJECT_PLAN_END_TIME: 'int|false|comment=计划结束时间',
        PROJECT_ACTUAL_START_TIME: 'int|false|comment=实际开始时间',
        PROJECT_ACTUAL_END_TIME: 'int|false|comment=实际结束时间',
        
        PROJECT_MANAGER_ID: 'string|false|comment=项目经理ID',
        PROJECT_BUSINESS_OWNER_ID: 'string|false|comment=业务负责人ID',
        PROJECT_TECHNICAL_OWNER_ID: 'string|false|comment=技术负责人ID',
        PROJECT_TEAM_MEMBER_IDS: 'array|true|default=[]|comment=团队成员ID数组',
        
        PROJECT_TAGS: 'array|true|default=[]|comment=标签数组',
        PROJECT_PROGRESS: 'int|true|default=0|comment=进度：0-100',
        
        PROJECT_REQUIREMENT_DOCS_COMPLETE: 'int|true|default=0|comment=需求文档是否完整：0=否, 1=是',
        PROJECT_DESIGN_DOCS_COMPLETE: 'int|true|default=0|comment=设计文档是否完整：0=否, 1=是',
        PROJECT_TEST_DOCS_COMPLETE: 'int|true|default=0|comment=测试文档是否完整：0=否, 1=是',
        PROJECT_PRODUCTION_DOCS_COMPLETE: 'int|true|default=0|comment=生产文档是否完整：0=否, 1=是',
        
        PROJECT_ORIGINAL_PROJECT_ID: 'string|false|comment=原始项目ID（如果是迭代项目）',
        PROJECT_RELATED_PROJECT_IDS: 'array|true|default=[]|comment=关联项目ID数组',
        
        PROJECT_GITEA_REPO_URL: 'string|false|comment=Gitea仓库URL',
        
        PROJECT_ADD_USER_ID: 'string|false|comment=创建人ID',
        PROJECT_ADD_TIME: 'int|true',
        PROJECT_EDIT_TIME: 'int|true',
        PROJECT_ADD_IP: 'string|false',
        PROJECT_EDIT_IP: 'string|false',
        PROJECT_ARCHIVE_TIME: 'int|false|comment=归档时间'
    };

    // 字段前缀
    static FIELD_PREFIX = "PROJECT_";

    /**
     * 项目类型：1=新产品开发, 2=客户定制, 3=技术预研, 4=迭代升级
     */
    static TYPE = {
        NEW: 1,
        CUSTOM: 2,
        RESEARCH: 3,
        ITERATION: 4
    };

    static TYPE_DESC = {
        NEW: '新产品开发',
        CUSTOM: '客户定制',
        RESEARCH: '技术预研',
        ITERATION: '迭代升级'
    };

    /**
     * 项目状态：1=待立项, 2=立项审核中, 3=已立项, 4=开发中, 5=测试中, 6=客户验证中, 7=量产准备, 8=试产中, 9=量产中, 10=已结项, 11=已取消
     */
    static STATUS = {
        PENDING: 1,
        APPROVING: 2,
        APPROVED: 3,
        DEVELOPING: 4,
        TESTING: 5,
        CUSTOMER_VALIDATING: 6,
        PRODUCTION_PREPARING: 7,
        TRIAL_PRODUCING: 8,
        MASS_PRODUCING: 9,
        COMPLETED: 10,
        CANCELLED: 11
    };

    static STATUS_DESC = {
        PENDING: '待立项',
        APPROVING: '立项审核中',
        APPROVED: '已立项',
        DEVELOPING: '开发中',
        TESTING: '测试中',
        CUSTOMER_VALIDATING: '客户验证中',
        PRODUCTION_PREPARING: '量产准备',
        TRIAL_PRODUCING: '试产中',
        MASS_PRODUCING: '量产中',
        COMPLETED: '已结项',
        CANCELLED: '已取消'
    };

    /**
     * 优先级：1=低, 2=中, 3=高, 4=紧急
     */
    static PRIORITY = {
        LOW: 1,
        MEDIUM: 2,
        HIGH: 3,
        URGENT: 4
    };

    static PRIORITY_DESC = {
        LOW: '低',
        MEDIUM: '中',
        HIGH: '高',
        URGENT: '紧急'
    };
}

module.exports = ProjectModelEnhanced; 